package cn.jbt.api.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.jbt.api.admin.annotation.Log;
import cn.jbt.api.admin.entity.SysDictOpt;
import cn.jbt.api.admin.service.ISysDictOptService;
import cn.jbt.common.PageQryParam;
import cn.jbt.common.PageQryResult;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/dictOpt")
@Slf4j
@AllArgsConstructor
public class SysDictOptController {

    private final ISysDictOptService iSysDictOptService;

    @PostMapping("/list")
    @SaCheckPermission("system:dictOpt:list")
    @Log(bizType = "查询", bizName = "分页查询字典选项")
    public PageQryResult<SysDictOpt> getAllByPage(@Valid @RequestBody PageQryParam<SysDictOpt> pageQryParam) {
        return iSysDictOptService.getAllByPage(pageQryParam);
    }

    @PostMapping("/add")
    @SaCheckPermission("system:dictOpt:add")
    @Log(bizType = "新增", bizName = "新增字典选项")
    public SysDictOpt add(@Valid @RequestBody SysDictOpt sysDictOpt) {
        return iSysDictOptService.add(sysDictOpt);
    }

    @PostMapping("/edit")
    @SaCheckPermission("system:dictOpt:edit")
    @Log(bizType = "编辑", bizName = "编辑字典选项")
    public SysDictOpt edit(@Valid @RequestBody SysDictOpt sysDictOpt) {
        return iSysDictOptService.edit(sysDictOpt);
    }

    @PostMapping("/del")
    @SaCheckPermission("system:dictOpt:del")
    @Log(bizType = "删除", bizName = "删除字典选项")
    public void del(@NotEmpty @RequestBody List<Long> ids) {
        iSysDictOptService.del(ids);
    }


}
